//
//  FeedbackController.m
//  XiaoMiao
//
//  Created by jinglian on 2018/2/10.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "FeedbackController.h"
#import "NSCommonTextView.h"

@interface FeedbackController ()
@property (weak, nonatomic) IBOutlet NSCommonTextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *feedbackButton;

/** <#属性#> */
@property (nonatomic, copy) NSString *alreadyFeedbackText;
@end

@implementation FeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"意见反馈";
    
    NSString *placeholder = @"请描述您遇到的问题或留下宝贵的意见，收到反馈后我们尽快为您处理";
    self.textView.ns_placeholder = placeholder;
    [self.feedbackButton addTarget:self action:@selector(feedbackButtonDidClick) forControlEvents:UIControlEventTouchUpInside]; 
}
 

- (void)feedbackButtonDidClick {
    [self.view endEditing:YES];
    
    if ([NSString app_isBlankString:self.textView.text]) {
        [KLProgressHUD showPromptHUDWithMessage:@"请输入反馈内容"];
        return;
    }
    
    if ([self.textView.text isEqualToString:self.alreadyFeedbackText]) {
        [KLProgressHUD showPromptHUDWithMessage:@"您已提交，请勿重复提交"];
        return;
    }
    
    [self request_feedback];
}

- (void)request_feedback {
    KLProgressHUD *progressHUD = [KLProgressHUD showWaitingHUDWithSuperView:self.view message:@"加载中.."];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"content"] = self.textView.text;
    
    [AppNetwork postWithUrl:kFeedbackPath params:param success:^(id response) {
        progressHUD.hidden = YES;
        
        [KLProgressHUD showSuccessHUDWithMessage:@"提交成功"];
        
        self.alreadyFeedbackText = self.textView.text;
        
    } fail:^(AppError *error) {
        progressHUD.hidden = YES;
        [KLProgressHUD showErrorHUDWithMessage:[error errorMessage]];
    }];
}

@end
